package com.sfh.cpc.note.model;

import com.sfh.cpc.com.entity.RspBase;
import com.sfh.cpc.com.req.ReqFile;
import com.sfh.cpc.com.req.ReqNoteAdd;
import com.sfh.lib.event.RxBusEventManager;
import com.sfh.lib.exception.HandleException;
import com.sfh.lib.mvvm.service.BaseViewModel;
import com.sfh.lib.rx.IResult;
import com.sfh.lib.rx.IResultSuccess;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/28
 */
public class NoteAddModel extends BaseViewModel {
    public void saveNote(final ReqNoteAdd req) {

        this.execute(false,req, new IResultSuccess<RspBase>() {
            @Override
            public void onSuccess(RspBase rspBase) throws Exception {
                if (rspBase.success()){
                    RxBusEventManager.postEvent(req);
                }
                setValue("onAddSuccess", rspBase);
            }
        });
    }

    public void updateFile(final String loanPath) {

        this.execute(new ReqFile(loanPath), new IResult<RspBase<String>>() {
            @Override
            public void onSuccess(RspBase<String> data) throws Exception {
                if (data.success()){
                    setValue("onSaveFile", loanPath,data.getData());
                }
            }
            @Override
            public void onFail(HandleException e) {
                showToast(e.getMsg());
                setValue("onSaveFile", loanPath,"");
            }
        });
    }

}
